// pages/index/index.js
Page({

  data: {
    autoplay: true,
    interval: 3000,
    duration: 500,
    dots: true,
    navItems: [{
      img: "/images/tabbar/topic-on.png",
      text: "真题狂练",
      color:'cyan',
      name:'crazy practice',
      type: 4,
      url: "/pages/exercises/exercises"
    }, {
      img: "/images/tabbar/collect.png",
      text: "我的收藏",
      color:'purple',
      name:'my stars',
      type: 0,
      url: "/pages/star/star"
    }, {
      img: "/images/tabbar/test-on.png",
      text: "分章学习",
      color:'blue',
      name:'points learn',
      type: 1,
      url: "/pages/partstudy/partstudy"
    }, {
      img: "/images/tabbar/err.png",
      text: "错题记录",
      color:'red',
      name:'wrong topic record',
      type: 2,
      url: "/pages/error/error"
    },{
      img: "/images/tabbar/test.png",
      text: "随机测试",
      color:'yellow',
      name:'random test',
      type: 3,
      url: "/pages/randomtest/randomtest"
    }
  ],
    banners: [{
        picUrl: "https://zhuge-1304126955.cos.ap-nanjing.myqcloud.com/images/3ac79f3df8dcd1009eb45920798b4710b9122f82.jpg"
      },
      {
        picUrl: "https://zhuge-1304126955.cos.ap-nanjing.myqcloud.com/images/9653.jpg_wh860.jpg",
      },
      {
        picUrl: "https://zhuge-1304126955.cos.ap-nanjing.myqcloud.com/images/9a362e0010c0d1d1c6f93ecc2c432519.jpg"
      }
    ]
  },
  onShow(){
  },
  handleToQueryCollection() {
   
  },
  handleNavTo(e) {
    //  console.log(e);
    let {
      url,
      type
    } = e.currentTarget.dataset;
    console.log(url, type);
    if (type != 1) {
      //登录之后才可以进行收藏和错题记录
      if(type == 0 || type == 2){
        var app = getApp();
        if(app.globalData.openId != ''){
          wx.navigateTo({
            url
          })
        }else{
          wx.showModal({
            title: '提示',
            content: '登陆后才可使用此功能',
            success (res) {
              if (res.confirm) {
                console.log('用户点击确定')
                
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }
      }else{
        wx.navigateTo({
          url
        })
      }
      
    } else{
      wx.switchTab({
        url
      })
    }
  },
  goToSearch(){
    wx.navigateTo({
      url: '../search/search',
    })
  }
})